package com.google.code.server4j.startup;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import com.google.code.server4j.connector.Connector;
import com.google.code.server4j.connector.HttpProcessor;
import com.google.code.server4j.connector.ProcessAdapter;
import com.google.code.server4j.connector.bio.BioConnector;
import com.google.code.server4j.connector.bio.BioHttpProcessor;
import com.google.code.server4j.connector.bio.BioProcessAdapter;
import com.google.code.server4j.handler.ServerHandler;
import com.google.code.server4j.util.BaseLifeCycle;

public class Startup{


	
	public static void main(String[] args) throws Exception {
		Connector conn = new BioConnector();
		conn.setPort(8080);

		HttpProcessor process = new BioHttpProcessor();
		ProcessAdapter adapter = new BioProcessAdapter();
		conn.setProcessAdapter(adapter);
		
		ServerHandler handler = new ServerHandler();
		process.setHandler(handler);
		process.setSocketTimeOut(20 * 1000);
		
		handler.setWebContext("E:\\webRoot");
		handler.setNotfountPage("JiahLee.jpg");
		
		BaseLifeCycle core = new Core();
		core.addLifeCycleBean(conn);
		core.addLifeCycleBean(process);
		core.addLifeCycleBean(handler);
		core.init();
		core.start();
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String line = br.readLine();
			if("exit".equals(line)) {
				core.stop();
				break;
			}
		}
	}

}
